package com.neu.envprotection.report.service.Impl;

import com.neu.envprotection.airQuality.dao.mapper.AirQualityMapper;
import com.neu.envprotection.airQuality.dto.resp.GetAQIDistributionRespDto;
import com.neu.envprotection.airQuality.dto.resp.GetAQITrendRespDto;
import com.neu.envprotection.airQuality.dto.resp.GetProvinceAQIRespDto;
import com.neu.envprotection.airQuality.feign.AirQualityFeign;
import com.neu.envprotection.common.resp.RestResp;
import com.neu.envprotection.feedback.dao.mapper.FeedbackMapper;
import com.neu.envprotection.feedback.dto.resp.ReportChinaChartsRespDto;
import com.neu.envprotection.feedback.feign.FeedbackFeign;
import com.neu.envprotection.report.service.ReportService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
@Slf4j
public class ReportServiceImpl implements ReportService {
    private final AirQualityFeign airQualityFeign;

    @Override
    public RestResp<List<GetProvinceAQIRespDto>> getProvinceAQI() {
        return RestResp.ok(airQualityFeign.getProvinceAQI().getData());
    }

    @Override
    public RestResp<List<GetAQIDistributionRespDto>> getAQIDistribution() {
        return RestResp.ok(airQualityFeign.getAQIDistribution().getData());
    }

    @Override
    public RestResp<List<GetAQITrendRespDto>> getAQITrend() {
        List<GetAQITrendRespDto> aqiTrend = airQualityFeign.getAQITrend().getData();
        return RestResp.ok(aqiTrend);
    }

    private final FeedbackFeign feedbackFeign;

    @Override
    public RestResp<List<Map<String, Integer>>> getChinaAQI() {
        List<Map<String, Integer>> list = new ArrayList<>();
        // 调用自定义的多表联查方法
        List<ReportChinaChartsRespDto> provinceAQIList = feedbackFeign.getProvinceAQI().getData();

        // 转换数据格式
        for (ReportChinaChartsRespDto provinceAQI : provinceAQIList) {
            Map<String, Integer> resultMap = new HashMap<>();
            resultMap.put(provinceAQI.getProvinceName(), provinceAQI.getAQILevel());
            list.add(resultMap);
        }

        return RestResp.ok(list);
    }
}
